﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace chen_bot_ui.Models
{
    public class ChatMsg
    {
        public string UserQQ { get; set; } = string.Empty;
        public int Time { get; set; }
        public string Context { get; set; } = string.Empty;
        public int Id { get; set; }
    }

    public class ChatMsgDb : DbContext
    {
        public DbSet<ChatMsg> ChatMsg { get; private set; }
        private readonly string _dbPath;

        private ChatMsgDb(string dbPath)
        {
            _dbPath = dbPath;
      
        }
  public static ChatMsgDb? CreateChatMsgDbConnect(string dbPath)
        {
            var db = new ChatMsgDb(dbPath);
            if (db.Database.EnsureCreated())
                return null;
            return db;
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlite($"Data Source={_dbPath}");
        }
    }
}
